﻿using Lunz.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace my.cache
{
    public class RedisCache : ICache
    {
        private readonly IRedisProvider redisProvider;
        public RedisCache(string redisConn)
        {
            redisProvider = new RedisProvider(redisConn);
        }
        public async Task<string> GetAsync(string key)
        {
            var result = await redisProvider.GetAsync(key);
            return result;
        }

        public async Task<T> GetAsync<T>(string key) where T : new()
        {
            var result = await redisProvider.GetAsync<T>(key);
            return result;
        }

        public async Task SetAsync(string key, object value, int expireSeconds = 0)
        {
            if (expireSeconds == 0)
            {
                await redisProvider.SetAsync(key, value);
                return;
            }
            await redisProvider.SetAsync(key, value, expireSeconds);
        }
    }
}
